This forum is closed to new posts and
responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:
There are two versions of each sort. There is a simple version that sorts your array. You hand an array to the sort and it sorts it. The second version takes two arrays. The first array is sorted and the second array is reordered in parallel. That is to say, the second array is switched around exactly as the first array was switched around.
The purpose of the "object" versions of the sorts is to allow you to sort complex data structures easily. Lets say you have an array of NotesDocuments and you want to sort that array based on an "Author" field. You quickly whip up an array with just the author names, and then you pass both arrays to the sort routine.
Open the Designer and look at the agents in the sort db. You'll find an agent that gives an example of object sorting. That code is almost exactly what you need. All you need to do is add another property to the class.
Here's how I would probably solve your problem...
In Declarations...
Class userlog
Public username As String
Public logentries As Long
Sub new( namein As String , entriesin As Long )
username = namein
logentries = entriesin
End Sub
End Class
In the code...
Dim userlogs() as variant ' array of userlog objects
Dim userlogkeys() as variant ' array of LogCount values for sorting
Dim userlogcounter as long
Redim userlogs( 0 ) ' not really needed, just like to have it
Redim userlogkeys( 0 ) ' not really needed, just like to have it
userlogcounter = -1 ' counter will be incremented before being used
' note that if you need to sort more than 32K values
' you can start userlogcounter at - 32,769 for up to 64K values
' but most people are comfortable with arrays starting at zero
'---the code you say you have that gets you the info ---
'---I don't have your code, so using UserName for the name---
'---and LogCount for the log entries.---
'---Replace those with the real variable names---
' The presumption here is that you're in a loop so we
' increment the counter
userlogcounter = userlogcounter + 1
' Next, redim the arrays using preserve so that you don't loose
' the data that's already in there.
Redim Preserve userlogs( userlogcounter )
Redim Preserve userlogkeys( userlogcounter )
' Next, create the arrays
userlogs( userlogcounter ) = New userlog( UserName , LogCount )
userlogkeys( userlogcounter ) = LogCount
'--- your code---
'--- end of your loop---
' Loop has ended. We created two arrays...one with all the data and one with sort keys
' Now sort the data. The data is sorted by LogCount and the userlogs are rearranged to match
Call qsort3obj_st ( userlogkeys , userlogs , "d" )
' That's it...you can access your data directly. Here are the top 5...
userlogs( 0 ).username
userlogs( 1 ).username
userlogs( 2 ).username
userlogs( 3 ).username
userlogs( 4 ).username
Note that this is off the top of my head...I haven't tested this so there may be a bug or two (mispelled names, etc.)
Note that you can extend the userlog class to contain any additional data you'd like to have. Just add new Public variables.
You need to learn to code like this...Notes is dead and you need to know object orientation and array manipulation like the back of your hand to code in any other system.
Feedback response number WLOO8Z8RLV created by ~Julia Feztoosterader on 10/19/2012